package net.aynt.blog.action;

import java.util.List;

import org.apache.commons.lang3.math.NumberUtils;

import net.aynt.blog.pojo.Article;
import net.aynt.blog.sys.AbstractAction;
import net.aynt.blog.util.PageInfo;
import net.aynt.core.mvc.WebContext;


public class IndexAction extends AbstractAction {
	
	@Override
	protected String process(WebContext rc, String[] p) {
		PageInfo pageInfo = new PageInfo();
		if (p != null && p.length > 0) {
			pageInfo.setPageIndex(NumberUtils.toInt(p[0], 1));
		}
		
		List<Article> articles = Article.INSTANCE.findHome(pageInfo);
		
		rc.setRequestAttr("articles", articles);
		rc.setRequestAttr("pageInfo", pageInfo);
		
		// 有标题图片的日志
		PageInfo pageInfo2 = new PageInfo();
		pageInfo2.setPageSize(5);
		List<Article> imgArticles = Article.INSTANCE.findTitleImages(pageInfo2);
		rc.setRequestAttr("imgArticles", imgArticles);
		
		return INDEX;
	}

}
